﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
namespace BLL
{
    public class UnityDependencyResolver : IDependencyResolver
    {
        IUnityContainer _container;

        public UnityDependencyResolver(IUnityContainer container)
        {
            _container = container;
        }

        public object GetService(Type serviceType)
        {
            object instance;
            try
            {
                instance = _container.Resolve(serviceType);
                if (serviceType.IsAbstract || serviceType.IsInterface)
                {
                    return null;
                }
                return instance;

            }
            catch (Exception e)
            { 
                return null;
            }
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return _container.ResolveAll(serviceType);

        }
    }
}
